<template>
	<el-container>
		<el-header style="font-size: 16px;font-weight: 600">系统服务设置</el-header>
		<el-main class="nopadding">
			<el-main>
				<el-form>
					<el-divider content-position="center">后台服务</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="后台服务器地址" label-width="150px">
								<el-input v-model="form.serverHost" placeholder="后台服务器地址"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">后台服务地址主要用动钉钉，微信消息的URL组成，同时也用作第三方插件的访问，如文件客户端，如PageOffice,Wps,OnlyOffice等。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="WEB服务器地址" label-width="150px">
								<el-input v-model="form.webHost" placeholder="WEB服务器地址"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">WEB应用服务器地址，主要用于消息提醒中的Url地址生成。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="桌面刷新间隔" label-width="150px">
								<el-input-number v-model="form.msgTime" placeholder="桌面刷新间隔"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">定时刷新桌面,获取个人相关信息。单位:(毫秒)</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="动态密码" label-width="150px">
								<el-switch v-model="form.verifyCode" active-value="1" inactive-value="0"></el-switch>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">登录时是启用动态密码验证！</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="错误次数" label-width="150px">
								<el-input-number v-model="form.errorCount" placeholder="错误次数"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">用户名密码验证出错次数,超过错误次数后锁定！</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="锁定时长" label-width="150px">
								<el-input-number v-model="form.reSetTime" placeholder="锁定时长"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">登陆失败后锁定时长，单位:(分钟)</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="附件打开方式" label-width="150px">
								<el-select v-model="form.officeType">
									<el-option value="0" label="卓正PageOffice"></el-option>
<!--									<el-option value="1" label="金格"></el-option>-->
									<el-option value="2" label="本地wps"></el-option>
									<el-option value="3" label="在线wps"></el-option>
									<el-option value="4" label="OnlyOffice"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">按系统实际情况选择文档在线打开方式</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="OFD打开方式" label-width="150px">
								<el-select v-model="form.ofdType">
									<el-option value="0" label="js插件打开"></el-option>
									<el-option value="1" label="福昕客户"></el-option>
									<el-option value="2" label="数科客户端"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">用js插件打开无其它功能,数科客户端打开 注:有编辑功能，但windows下只能用IE，fireFox 52版本及以下版本，国产化支持。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="文件预览方式" label-width="150px">
								<el-select v-model="form.openOnLineFlag">
									<el-option value="0" label="POI方式"></el-option>
									<el-option value="1" label="OpenOffice"></el-option>
									<el-option value="2" label="前台方式"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">POI方式为系统内置,openOffice为OpenOffice第三方服务,前台方式为VUE组件预览，注只能为(.docx,xlsx,.pdf)格式，其它格式则自动转为POI方式</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="文件预览大小" label-width="150px">
								<el-input-number v-model="form.previewFileSize" placeholder="文件预览大小"></el-input-number>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">根据服务器性能与系统运行情况合理设置预览文件大小，文件转换功能消耗服务器资源较多，推荐5M以内。单位:(M)</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="临时目录" label-width="150px">
								<el-input v-model="form.poiTempPath" placeholder="临时目录"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">文档格式文件转换临时目录,目录创建位置在系统附件目录中。例如:tmppath则为${app.attachpath}/tmppath</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">WPS在线编辑设置</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="在线WPS AppId" label-width="150px">
								<el-input v-model="form.wpsAppId" placeholder="在线WPS AppId,测试AppId:SX20230918IBXHLW"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">WPS在线服务申请的AppId。V3版https://solution.wps.cn 测试AppId:SX20230918IBXHLW</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="在线WPS App Secret" label-width="150px">
								<el-input v-model="form.wpsAppSecret" placeholder="在线WPS"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">WPS在线服务申请的AppSecret。V3版https://solution.wps.cn AppSecret测试AppSecret:JPJkpQvQSTSJEiTMSfUvRDwgAHSBxUQg</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">OnlyOffice在线文档设置</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="OnlyOffice服务器" label-width="150px">
								<el-input v-model="form.onlyOfficeHost" placeholder="OnlyOffice服务器"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">OnlyOffice服务器主机地址。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">全文检索</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="全文检索目录" label-width="150px">
								<el-input v-model="form.luceneCache" placeholder="全文检索目录"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">Lucene全文检索缓存文件目录。目录创建位置在系统附件目录中。例如:lucene/index则为${app.attachpath}/lucene/index</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="档案检索目录" label-width="150px">
								<el-input v-model="form.archivesCache" placeholder="档案检索目录"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">档案全文检索缓存文件目录。目录创建位置在系统附件目录中。例如:archivescache/index则为${app.attachpath}/archivescache/index</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">百度地图</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度地图App_Key" label-width="150px">
								<el-input v-model="form.mapAppKey" placeholder="百度地图App_Key"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">百度地图经纬度定位,用户可更新成自己单位的 申请地址：http://lbsyun.baidu.com</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">百度网盘</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度网盘App_Id" label-width="150px">
								<el-input v-model="form.bpanAppId" placeholder="百度网盘App_Id"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">百度云盘相关应用申请,用户可更新成自己单位的 申请地址：https://pan.baidu.com/union/document/</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度网盘App_Key" label-width="150px">
								<el-input v-model="form.bpanAppKey" placeholder="百度网盘App_Key"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">百度云盘相关应用申请,用户可更新成自己单位的 申请地址：https://pan.baidu.com/union/document/</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度网盘Secret_Key" label-width="150px">
								<el-input v-model="form.bpanSecretKey" placeholder="百度网盘Secret_Key"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">百度云盘相关应用申请,用户可更新成自己单位的 申请地址：https://pan.baidu.com/union/document/</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度网盘Sign_Key" label-width="150px">
								<el-input v-model="form.bpanSignKey" placeholder="百度网盘Sign_Key"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">百度云盘相关应用申请,用户可更新成自己单位的 申请地址：https://pan.baidu.com/union/document/</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度网盘备份目录" label-width="150px">
								<el-input v-model="form.bpanPath" placeholder="百度网盘备份目录"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">百度云盘备份目录设置,例如："/back"</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="百度网盘Code" label-width="150px">
								<el-input v-model="form.bpanCode" placeholder="百度网盘Code"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<el-button type="primary" @click="getBpanCode">获取Code</el-button>
								<span style="color: red;">code只能使用一次，10分钟未被使用自动过期。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">国际化设置</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="国际化设置" label-width="150px">
								<el-switch v-model="form.langFlag" active-value="1" inactive-value="0"></el-switch>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">是否启用国际化语言环境,支持中文，英文，繁体。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">登录设置</el-divider>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="记住密码" label-width="150px">
								<el-switch v-model="form.remUserPass" active-value="1" inactive-value="0"></el-switch>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">是否允许用户记住用户名密码。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="找回密码" label-width="150px">
								<el-switch v-model="form.findPass" active-value="1" inactive-value="0"></el-switch>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">是否允许用户通过邮件找回密码。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="6">
							<el-form-item label="全网变灰" label-width="150px">
								<el-switch v-model="form.greyStatus" active-value="1" inactive-value="0"></el-switch>
							</el-form-item>
						</el-col>
						<el-col :lg="6">
							<el-form-item v-if="form.greyStatus==='1'">
								<el-date-picker v-model="form.greyEndTime" placeholder="结束时间" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">一般用于公祭日,当系统时间在结束时间之前,系统界面将全面变成灰色！</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-divider content-position="center">通讯加密设置</el-divider>
					<el-row :gutter="24">
						<el-col :lg="6">
							<el-form-item label="加密方式" label-width="150px">
								<el-select v-model="form.encryptionType">
									<el-option value="0" label="RSA"></el-option>
									<el-option value="1" label="SM2"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="6">
							<el-button type="primary" @click="createKey">生成密钥</el-button>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">设置系统参数加密方式。请注意公钥密钥对应关系。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="24">
							<el-form-item label="公钥" label-width="150px">
								<el-input v-model="form.publicKey" placeholder="公钥" type="textarea" rows="5"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="24">
							<el-form-item label="私钥" label-width="150px">
								<el-input v-model="form.privateKey" placeholder="私钥"  type="textarea" rows="5"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</el-main>
		</el-main>
		<el-footer class="footer">
			<el-button type="primary" @click="setSysConfig">设置</el-button>
		</el-footer>
	</el-container>
	<createKeyDialog v-if="dialog.show" ref="keyDialog" @success="handleDicSuccess" @closed="dialog.show=false"></createKeyDialog>
</template>

<script>
import createKeyDialog from './createKeyDialog'
export default {
	name: 'config',
	components:{
		createKeyDialog,
	},
	data() {

		return {
			dialog: {
				show:false
			},
			form: {
				webHost:'',
				msgTime: 60000,
				verifyCode: '0',
				errorCount: '4',
				reSetTime: '100',
				officeType: '0',
				ofdType: '0',
				openOnLineFlag: '2',
				poiTempPath: '',
				serverHost: '',
				wpsAppId: '',
				previewFileSize:5,
				wpsAppSecret: '',
				onlyOfficeHost:'',
				luceneCache:'',
				mapAppKey:'',
				bpanAppId:'',
				bpanAppKey:'',
				bpanSecretKey:'',
				bpanSignKey:'',
				bpanPath:'',
				bpanCode:'',
				langFlag:'0',
				remUserPass:'0',
				findPass:'0',
				greyStatus:'0',
				greyEndTime:'',
				encryptionType:'0',
				publicKey:'',
				privateKey:'',
			},
		}
	},
	mounted() {
		this.getSysConfig();
	},
	methods: {
		createKey(){
			this.dialog.show = true
			this.$nextTick(() => {
				this.$refs.keyDialog.open().setData(this.form.encryptionType)
			})
		},
		getBpanCode(){
			console.log(this.form.bpanAppKey);
			if(this.form.bpanAppKey==undefined||this.form.bpanAppKey=='')
			{
				this.$alert("百度云盘APP_KEY不能为空", "提示", {type: 'error'})
			}else {
				window.open("https://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id="+this.form.bpanAppKey+"&redirect_uri=oob&scope=basic,netdisk&display=tv&qrcode=1&force_login=1"+"&ddtab=true")
			}
		},
		async setSysConfig() {
			var res = await this.$API.system.sysConfig.setSysConfig.post(this.form);
			if (res.code == 200) {
				this.$message.success(res.message)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getSysConfig() {
			var res = await this.$API.system.sysConfig.getSysConfig.get();
			if (res.code == 200) {
				this.form = res.data;
				this.form.bpanCode='';
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		handleDicSuccess(data){
			this.form.publicKey = data.publicKey;
			this.form.privateKey = data.privateKey;
		}
	}
}
</script>

<style scoped>
.footer {
	text-align: center;
}
</style>
